<template>
  <div class="white-module">
    <div class="c">
      <div class="content">
        <div class="header_title">大赛证书查询平台</div>
        <div v-if="tableData.list.length>0" style="float: left;text-align: left;margin-left: 20px;">
          <img :src="tableData.list[0].header" width="100" height="140"/>
          <div class="title">{{tableData.list[0].userName}}</div>
          <div class="title">{{tableData.list[0].company}}</div>
        </div>
        <div class="global-table">
          <el-table
              :data="tableData.list"
              :header-cell-style="{
              background: '#F5F7FA',
              color: '#333',
          }"
              style="width: 100%"
          >
            <el-table-column prop="matchName" label="赛事名称" >
              <template #default="scope">
                {{scope.row.matchName}} {{scope.row.matchNameExt?'（'+scope.row.matchNameExt+'）': ''}}
              </template>
            </el-table-column>
            <el-table-column prop="itemName" label="赛项" width="200">
              <template #default="scope">
                {{scope.row.itemName}}（{{scope.row.groupName}}）
              </template>
            </el-table-column>
            <el-table-column prop="matchLevel" label="层级" width="80">
              <template #default="scope">
                {{scope.row.matchLevel ==1 ? '国赛': '省赛'}}
              </template>
            </el-table-column>
            <el-table-column prop="company" label="选手单位" width="200"/>
            <el-table-column prop="score" label="奖项" width="80"/>
            <el-table-column prop="teacher" label="指导老师" width="120"/>
            <el-table-column prop="certificate" label="证书编号" width="190"/>
            <el-table-column label="操作" width="120">
              <template #default="scope">
                <span class="table-text-btn" v-if="scope.row.url" @click="viewUrl(scope.row.url)">查看</span>
                <span class="table-text-btn" v-if="scope.row.url" @click="downLoadFile(scope.row.url, realName + '-' + scope.row.certificate+'.png')">下载</span>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <el-row class="global-pagination">
          <el-col :span="8" class="total"> 共搜索 {{tableData.list.length}} 条数据 </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { reactive, ref } from "vue";
import {useRoute} from "vue-router";
import baseService from "@/service/baseService";
import {ElMessage} from "element-plus";
import app from "@/constants/app";
import {getCache} from "@/utils/cache";
const route = useRoute();

const tableData = reactive({
  list: []
});

const showViewUrlFlag = ref(false);


const certificateJson = getCache('certificate', { isSessionStorage: true }, {});
const realName = certificateJson.realName;
const idCard = certificateJson.idCard;
const certificate = certificateJson.certificate;

//查看证书
const viewUrl = (url: string) => {
  window.open(url);
};

// 查询证书
const queryCertificateBy = () => {
  baseService
      .post("/front/spuser/queryCertificateBy", {realName, idCard, certificate})
      .then((res) => {
            if (res.code === 0) {
              tableData.list = res.data;
            } else {
              ElMessage.error(res.msg);
            }
          }
      );
};

const downLoadFile = (url: string, name: string) => {
  let a = document.createElement('a');
  let evt = document.createEvent('MouseEvents');
  a.download = '晋级列表';
  a.href = app.api+"/front/download?imageUrl="+ url +"&fileName=" + name;
  evt.initEvent('click',true,true);
  a.dispatchEvent(evt);
  window.URL.revokeObjectURL(a.href);
}


queryCertificateBy();

</script>


<style lang="scss" scoped >
.white-module {
  padding-top: 20px;
}


.header_title{
  text-align: center;
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 25px;
}
.title {
  /*display: flex;*/
  align-items: center;
  font-size: 16px;
  font-weight: $font-weight-bold;
  margin-bottom: 16px;

  span {
    width: 4px;
    height: 12px;
    background: #00a0e9;
    margin-right: 7px;
  }
}

.troops {
  position: relative;
  margin: 0px 0px 10px 20px;

  img {
    width: 579px;
  }

  .c {
    position: absolute;
    left: 0px;
    top: 0px;
    width: 532px;
    line-height: 54px;
    border-radius: 6px;

    span {
      font-size: 16px;
      font-weight: $font-weight-bold;
      margin-left: 24px;
      margin-right: 11px
    }

  ;

    span:nth-child(3) {
      margin-left: 40px;
    }
  }
}

.title {
  display: flex;
  justify-content: space-between;
  padding: 0px 20px;

  .left {
    font-size: 16px;
    font-weight: $font-weight-bold;
  }

;

  .right {
    color: #959CA9;

    .el-button {
      margin-left: 16px;
    }

    span {
      color: #FF8F3C;
    }
  }
}

.global-table {
  margin-top: 15px;
  padding: 0px 20px;
  .unread-dot {
    display: inline-block; /* 将 span 元素设置为块级元素 */
    width: 8px; /* 确定红点大小 */
    height: 8px;
    background-color: red; /* 设置背景颜色 */
    border-radius: 50%; /* 将红点设置为圆形 */
    margin-left: -3px; /* 如果和文字在一行上，需要设置左侧间距 */
    margin-top: -15px;
    vertical-align: middle; /* 设置垂直对齐方式为中间对齐 */
  }
}

.popper-menu {
  border: 0px !important;

  .el-menu {
    padding: 0px !important;
    background-color: #008fd1 !important;

    .el-menu-item-group__title {
      padding: 0px;
    }

    .el-menu-item:hover {
      background-color: #ffffff !important;
      color: #00a0e9;
    }

    .el-menu-item.is-active {
      background-color: #ffffff !important;
    }
  }
}</style>
